import  requests,unittest

# url='http://10.59.9.14:7003/api/public/login'
# method='POST'
# json={"username":"17733058407","password":"li123456"}
#
# print(requests)


class A3mall(unittest.TestCase):
    token = None
    #login 登录
    def test_A3mall_01_login(self):

        url = 'http://10.59.9.14:7003/api/public/login'
        json = {"username": "17733058407", "password": "li123456"}
        login = requests.post(url=url,
                              json=json)
        print(login.json())
        A3mall.token =login.json()['data']['token']
        print(A3mall.token)
    #info 我的
    def test_A3mall_02_info(self):
        url='http://10.59.9.14:7003/api/ucenter/info'
        headers={'Auth-Token':'Bearer '+A3mall.token}
        info=requests.get(url=url,headers=headers)
        print(info.json())
    #send 签到
    def test_A3mall_03_send(self):
        url='http://10.59.9.14:7003/api/sign/send'
        headers={'Auth-Token':'Bearer '+A3mall.token}
        send=requests.get(url=url,headers=headers)
        print(send.json())

    #seach 搜索
    def test_A3mall_04_seach(self):
        url='http://10.59.9.14:7003/api/search'
        seach=requests.get(url=url)
        print(seach.json())

    # seach_list 搜索列表
    def test_A3mall_05_seach_list(self):
        spid=None
        url='http://10.59.9.14:7003/api/search/list?page=1&keywords=%E7%83%AD&type=0&sort=1'
        seach_list=requests.get(url=url)
        print(seach_list.json())
        A3mall.spid=seach_list.json()['data']['list'][0]['id']
        print(A3mall.spid)

    #商品详情
    def test_A3mall_06_view(self):
        url='http://10.59.9.14:7003/api/goods/view?id=47'
        view=requests.get(url=url)
        print(view.json())

    #加入购物车
    def test_A3mall_07_add(self):
        url='http://10.59.9.14:7003/api/cart/add'
        json={"id":47,"sku_id":"","num":1}
        headers = {'Auth-Token': 'Bearer ' + A3mall.token}
        add=requests.post(url=url,json=json,headers=headers)
        print(add.json())

    if __name__ == '__main__':
        unittest.main()